package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.calibrationRecordPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface calibrationRecordMapp {
    //从基础信息表中拿到所有数据后，拿到一行插入一行校准记录数据
    @DS("newMscLowCodeFormal")
    //定义将接收到的数据分别放入到数据库的哪个字段
    @Insert("insert into ddm_calibration_record(" +
            "id, create_time, update_time," +
            "creator, sys_update_user, sys_deleted," +
            "basic_information_id, number, name," +
            "name_english, name_russian, specification, " +
            "standard_value, upper_tolerance, lower_tolerance, " +
            "calibration_cycle, calibration_result, calibration_value," +
            "calibration_date, historical_information,`group` )" +
            "VALUES (" +
            "#{id}, #{create_time}, #{update_time}," +
            "#{creator}, #{sys_update_user}, #{sys_deleted}," +
            "#{basic_information_id}, #{number}, #{name}," +
            "#{name_english}, #{name_russian}, #{specification}, " +
            "#{standard_value}, #{upper_tolerance}, #{lower_tolerance}, " +
            "#{calibration_cycle}, #{calibration_result}, #{calibration_value}," +
            "#{calibration_date}, #{historical_information}, #{group} )")
     void insertOneRow(calibrationRecordPojo pojo);

    //对一个字段，从老值更改为新值
    @DS("newMscLowCodeFormal")
    @Update("update ddm_calibration_record set ${fieldName}=#{newData} where ${fieldName}=#{old}")
    void editByField(String fieldName, String old, String newData);

    //查询所有数据
    @DS("newMscLowCodeFormal")
    @Select("Select * from ddm_calibration_record where sys_deleted=0")
    List<calibrationRecordPojo> queryAll();

    //根据id编辑某一行校准记录数据
    @DS("newMscLowCodeFormal")
    @Update("update ddm_calibration_record " +
            //!!!set必须和上一行之间加空格
            "set " +
            "id=#{id}," +
            "create_time=#{create_time}," +
            "update_time=#{update_time}," +
            "creator=#{creator}," +
            "sys_update_user=#{sys_update_user}," +
            "sys_deleted=#{sys_deleted}," +
            "basic_information_id=#{basic_information_id}," +
            "number=#{number}," +
            "name=#{name}," +
            "name_english=#{name_english}," +
            "name_russian=#{name_russian}," +
            "specification=#{specification}," +
            "standard_value=#{standard_value}," +
            "upper_tolerance=#{upper_tolerance}," +
            "lower_tolerance=#{lower_tolerance}," +
            "calibration_cycle=#{calibration_cycle}," +
            "calibration_result=#{calibration_result}," +
            "calibration_value=#{calibration_value}," +
            "calibration_date=#{calibration_date}," +
            "historical_information=#{historical_information}, " +
            "`group`=#{group}" +
            //明确修改的是某一行，而不是将所有行全部修改（如果不写的话会默认修改所有行数据）
            //!!!where前必须加空格
            " where id=#{id}")
    void editOneById(calibrationRecordPojo pojo);

    //根据编号，修改删除标记位
    @DS("newMscLowCodeFormal")
    @Update("update ddm_calibration_record " +
            "set " +
            "sys_deleted=#{deleteVal} " +
            "where number=#{fieldVal}")
    void editByFieldInt(String fieldName, String fieldVal, int deleteVal);
}
